import { defineConfig } from 'vite'
import path from 'node:path'
import { fileURLToPath, URL } from 'node:url'
import electron from 'vite-plugin-electron/simple'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [
    vue(),
    electron({
      main: {
        entry: 'electron/main.ts',
      },
      preload: {
        input: path.join(__dirname, 'electron/preload.ts'),
      },
      renderer: process.env.NODE_ENV === 'test' ? undefined : {},
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  build: {
    minify: 'esbuild', // 采用更快的 esbuild 压缩
    sourcemap: false, // 关闭 Source Map
    assetsInlineLimit: 4096, // 禁止 base64 内嵌
    rollupOptions: {
      external: ['electron'], // 不打包 electron
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return 'vendor' // 分离依赖
          }
        }
      }
    }
  }
})
